import http from './interface'
import store from '@/store'
//设置请求前拦截器
http.interceptor.request = (config) => {
	config.header = {
		'token': store.state.shopInfo.token,
	}
	
}
//设置请求结束后拦截器
http.interceptor.response = (response) => {
	if(response.data.code==20001){
		//未登录
		store.commit('logout')
		uni.navigateTo({
			url:'/pages/user/login'
		})
		return;
	}
	if(response.data.code==20002){
		//身份认证过期
		store.commit('logout')
		uni.navigateTo({
			url:'/pages/user/login'
		})
		return;
	}
	
}

/**
 * 将业务所有接口统一起来便于维护
 * 如果项目很大可以将 url 独立成文件，接口分成不同的模块
 * 
 */

//商家登陆
export const login = (data) => {

	return http.request({
		url: 'api/user/shopLogin',
		method: 'POST',
		data,
	})
}
export const resetShopPassword = (data) => {

	return http.request({
		url: 'api/user/resetShopPassword',
		method: 'POST',
		data,
	})
}
export const getVerificationCode = (data) => {

	return http.request({
		url: 'api/user/getVerificationCode',
		method: 'POST',
		data,
	})
}
export const checkShopLogin = (data) => {

	return http.request({
		url: 'api/user/checkShopLogin',
		method: 'POST',
		data,
	})
}
export const orderInfoByOrderNumber = (data) => {

	return http.request({
		url: 'api/orders/orderInfoByOrderNumber',
		method: 'POST',
		data,
	})
}

export const destroyOrder = (data) => {

	return http.request({
		url: 'api/orders/destroyOrder',
		method: 'POST',
		data,
	})
}

export const getSalesData = (data) => {

	return http.request({
		url: 'api/orders/shopIncome',
		method: 'POST',
		data,
	})
}

export const getShopOrders = (data,pageNum,pageSize) => {
	http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token': store.state.shopInfo.token
		}
	}
	return http.request({
		url: 'api/shop/getShopOrders',
		method: 'POST',
		data,
	})
}

export const getOrdersClassifyNumber = (data) => {

	return http.request({
		url: 'api/shop/getOrdersClassifyNumber',
		method: 'POST',
		data,
	})
}
export const getShopOrdersInfo = (data) => {

	return http.request({
		url: 'api/orders/getShopOrdersInfo',
		method: 'POST',
		data,
	})
}

export const updateTakes = (data) => {

	return http.request({
		url: 'api/orders/updateStatus',
		method: 'POST',
		data,
	})
}
export const getRefundOrdersInfo = (data) => {

	return http.request({
		url: 'api/shop/getRefundOrdersInfo',
		method: 'POST',
		data,
	})
}



export const subRefund = (data) => {

	return http.request({
		url: 'api/orders/isRefund',
		method: 'POST',
		data,
	})
}
export const shop_scan_QR_codes = (data) => {

	return http.request({
		url: 'api/payment/shop_scan_QR_codes',
		method: 'POST',
		data,
	})
}

export const scanTheMember = (data) => {

	return http.request({
		url: 'api/payment/scan_the_member',
		method: 'POST',
		data,
	})
}
export const member_deduct_money = (data) => {
	return http.request({
		url: 'api/payment/member_deduct_money',
		method: 'POST',
		data,
	})
}


export default {
	member_deduct_money,
	scanTheMember,
	shop_scan_QR_codes,
	subRefund,
	getRefundOrdersInfo,
	updateTakes,
	getShopOrdersInfo,
	getOrdersClassifyNumber,
	getShopOrders,
	getSalesData,
	destroyOrder,
	orderInfoByOrderNumber,
	checkShopLogin,
	getVerificationCode,
	login,
	resetShopPassword
	

}
